
Page({

    /**
     * 页面的初始数据
     */


    data: {
        wordBookList: [],
        userId: null,
        userInfo: null,
      },
      
      onLoad: function() {
        var userInfo = wx.getStorageSync('userInfo');
        this.setData({ userInfo: userInfo });
        console.log(this.data.userInfo)
          var userId = wx.getStorageSync('userId');
          this.setData({
            userId: userId,
          })
          console.log(this.data.userId)
        },

      
      
      onShow: function() {
        let that = this;
        wx.request({
          url: 'http://47.95.223.130:8083/Book/get',
          method: 'GET',
          success: function(res) {
            if(res.data.code === 200) {
              that.setData({
                wordBookList: res.data.data
              });
              console.log(res)
              console.log(that.data.wordBookList)
              console.log(that.data.userInfo.uuid)
            } else {
              wx.showToast({
                title: res.data.message,
                icon: 'none'
              });
              console.log(res)
            }
          }
        });
      },


       Console1:function(event) {
           console.log(this.data.wordBookList[0].bookId)
           var userId1 = wx.getStorageSync('userId');
           var bookId1 = wx.getStorageSync('bookId');
           var userInfo = wx.getStorageSync('userInfo');
           console.log(userId1)
           console.log(bookId1)
           console.log(userInfo)
       },

       Console2:function(event) {
        wx.setStorageSync('userId', '767e7bdb3ce711eea9ec0242ac110002');
     },
      
      addWordBook1: function(event) {
        let that = this;
        let bookId = this.data.wordBookList[0].bookId;
        
        wx.request({
          url: 'http://47.95.223.130:8083/Book/insertBook',
          method: 'POST',
          data: {
            userId: that.data.userInfo.uuid,
            bookId: that.data.wordBookList[0].bookId
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
        },
          success: function(res) {
            if(res.data.code === 200) {
                console.log(that.data.userInfo.uuid)
                console.log(that.data.wordBookList[0].bookId)
              wx.showToast({
                title: '添加成功!',
                icon: 'success'
              });
              console.log(res)
              wx.setStorageSync('bookId', bookId);
            } else {
              wx.showToast({
                title: res.data.message,
                icon: 'none'
              });
            }
          }
        });
      },

      addWordBook2: function(event) {
        let that = this;
        let bookId = this.data.wordBookList[1].bookId;
        wx.request({
          url: 'http://47.95.223.130:8083/Book/insertBook',
          method: 'POST',
          data: {
            userId: that.data.userInfo.uuid,
            bookId: that.data.wordBookList[1].bookId
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
        },
          success: function(res) {
            if(res.data.code === 200) {
                console.log(that.data.userInfo.uuid)
                console.log(that.data.wordBookList[1].bookId)
                wx.showToast({
                  title: '添加成功!',
                  icon: 'success'
                });
                console.log(res)
                wx.setStorageSync('bookId', bookId);
            } else {
              wx.showToast({
                title: res.data.message,
                icon: 'none'
              });
            }
          }
        });
      },

      addWordBook3: function(event) {
        let that = this;
        let bookId = this.data.wordBookList[2].bookId;
        wx.request({
          url: 'http://47.95.223.130:8083/Book/insertBook',
          method: 'POST',
          data: {
            userId: that.data.userInfo.uuid,
            bookId: bookId
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
        },
          success: function(res) {
            if(res.data.code === 200) {
                wx.showToast({
                  title: '添加成功!',
                  icon: 'success'
                });
                console.log(res)
                wx.setStorageSync('bookId', bookId);
            } else {
              wx.showToast({
                title: res.data.message,
                icon: 'none'
              });
            }
          }
        });
      },

      addWordBook4: function(event) {
        let that = this;
        let bookId = this.data.wordBookList[3].bookId;
        wx.request({
          url: 'http://47.95.223.130:8083/Book/insertBook',
          method: 'POST',
          data: {
            userId: that.data.userInfo.uuid,
            bookId: bookId
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
        },
          success: function(res) {
            if(res.data.code === 200) {
                wx.showToast({
                  title: '添加成功!',
                  icon: 'success'
                });
                console.log(res)
                wx.setStorageSync('bookId', bookId);
            } else {
              wx.showToast({
                title: res.data.message,
                icon: 'none'
              });
            }
          }
        });
      },

      addWordBook5: function(event) {
        let that = this;
        let bookId = this.data.wordBookList[4].bookId;
        wx.request({
          url: 'http://47.95.223.130:8083/Book/insertBook',
          method: 'POST',
          data: {
            userId: that.data.userInfo.uuid,
            bookId: bookId
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
        },
          success: function(res) {
            if(res.data.code === 200) {
                wx.showToast({
                  title: '添加成功!',
                  icon: 'success'
                });
                console.log(res)
                wx.setStorageSync('bookId', bookId);
            } else {
              wx.showToast({
                title: res.data.message,
                icon: 'none'
              });
            }
          }
        });
      },

    /**
     * 生命周期函数--监听页面加载
     */


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})